﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lswweb.Domain;
using Lswweb.Model;

namespace Lswweb.Controls
{
    public abstract class UpFileShowBase : ControlBase
    {
        public int? UpFileId
        {
            get;
            set;
        }

        protected override void Render(HtmlTextWriter writer)
        {
            UpFileInfo info = UpFiles.GetFile(UpFileId == null ? 0 : (int)UpFileId);
            if (info == null)
                return;

            Render(writer,info);
        }

        protected abstract void Render(HtmlTextWriter writer,UpFileInfo info);
    }

    public class UpFileImageShow : UpFileShowBase
    {
        protected override void Render(HtmlTextWriter writer, UpFileInfo info)
        {
            string str = string.Format(
                "<a href=\"{0}\"><img src=\"{1}\" width=\"{3}\" height=\"{4}\" alt=\"{2}\"></a>", 
                info.LinkUrl, 
                info.FileUrl, 
                info.FileName,
                Width==null?string.Empty:Width.ToString(),
                Height==null?string.Empty:Height.ToString());

            writer.Write(str);
        }

        public int? Width
        {
            get;
            set;
        }

        public int? Height
        {
            get;
            set;
        }
    }

    public class UpFileShow : UpFileShowBase
    {
        protected override void Render(HtmlTextWriter writer, UpFileInfo info)
        {
            string str= string.Format("<a href=\"{0}\">{1}</a>", info.FileUrl, info.FileName);
            writer.Write(str);
        }
    }
}
